{include file="header/index" /}
<div class="newContentBox">
    <!-- 分割部分 -->
    <div class="newListPart">

<!--        <div class="newTitleBox">-->
<!--            <span class="layui-inline newListTitle">工程师傅列表</span>-->
<!--        </div>-->
        <form method="get" name="searchuser" action="#" class="layui-form">
            <div class="newForm flex_between">
                <div>
                    <div class="newGroup">
                        <div class="newGroupInput">
                            <input type="text" value="" id="keyword" placeholder="请输入姓名|手机号" class="layui-input-search cover_layui_i"/>
                        </div>
                    </div>
                    <div class="newGroup newBtnBox">
                        <a id="search" class="newBtnSearch newBtnPrimary">搜索</a>
                    </div>
                </div>
                <div>
                    <div class="newGroup newBtnBox">
                        <a href='{:url("Performance/engineerslist")}' class="newBtnDefault newBtnAllBorderColor" title="查看所有工程的业绩明细">业绩明细</a>
                    </div>
                </div>

            </div>
        </form>
        <div class="newTableBox">
            <table class="layui-table">
                <div>
                    <div style="width: 200px;float: left;">账户余额总和:<span id="total_money" style="color: red;font-size: 16px;">--</span></div>
                    <div>冻结积分总和:<span id="total_temp_money" style="color: red;font-size: 16px;">--</span></div>
                </div>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>姓名</th>
                    <th>编号</th>
                    <th>手机号</th>
                    <th>账户积分</th>
                    <th>冻结积分</th>
                    <th>所属省级承包商</th>
                    <th>所属区县级承包商</th>
                    <th>状态</th>
                    <th>注册时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <!--套数据 laypage-->
                <script id="list-template" type="text/html">
                    {{# for(var i=0;i<d.length;i++){  }}
                    <tr>
                        <td width="30px">{{d[i].engineers_id}}</td>
                        <td>{{d[i].engineers_name}}</td>
                        <td>{{d[i].engineers_number}}</td>
                        <td>{{d[i].engineers_phone}}</td>
                        <td>{{d[i].money}}</td>
                        <td>{{d[i].temp_money}}</td>
                        <td>{{d[i].o_name}}</td>
                        <td>{{d[i].a_name}}</td>
                        <td>{{d[i].engineers_status}}</td>
                        <td>{{d[i].reg_time}}</td>
                        <td>
                            <a href="javascript:;" onclick="editEngineers({{d[i].engineers_id}})" class="newBtnDefault">
                                编辑</a>&nbsp;
                            <a href='{:url("Performance/engineerslist")}?contract_number={{d[i].engineers_phone}}' class="newBtnDefault">
                                业绩</a>&nbsp;
                            <a href='{:url("Engineers/fundsRecord")}?id={{d[i].engineers_id}}' class="newBtnDefault">
                                账户记录</a>&nbsp;
                        </td>
                    </tr>
                    {{# } }}
                </script>
                <tbody id="list-content"></tbody>
            </table>
            <!--用来存当前页码数-->
            <input type="hidden" value="1" id="curr_" />
            <div class="laypage">
                <div class="laypage_total">共<span id="total_number"></span>条数据&nbsp;&nbsp;<span id="allpage"></span></div>
                <div class="laypage_skip" id="AjaxPage"></div>
            </div>
        </div>

    </div>
</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl;
    $.ajaxSetup({headers: {token: $.cookie('token'),company: $.cookie('company_id')}});;

    Ajaxpage();
    function Ajaxpage(curr){
        var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
        $("#curr_").val(curr);
        var keyword = $('#keyword').val();
        var request_data = {};
        request_data.keyword = keyword;
        request_data.page = curr || 1;
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Engineers/engineersList", request_data, function(data){
            layer.close(loadingFlag);
            var page = data.data.page;
            $("#total_number").text(page.total_number);
            $("#total_money").text(page.total_money);
            $("#total_temp_money").text(page.total_temp_money);
            data = data.data.data;
            if(data==''){
                $("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            }else{
                var tpl = document.getElementById('list-template').innerHTML;
                laytpl(tpl).render(data, function(html){
                    document.getElementById('list-content').innerHTML = html;
                });
            }
            //分页
            laypage.render({
                elem: 'AjaxPage' //分页容器的id
                ,count: page.total_number //总条数
                ,limit: page.row //每页条数
                ,skin: '#1AB5B7' //自定义选中色值
                ,curr: curr || 1
                ,layout: [ 'prev', 'page', 'next', 'skip']
                //,skip: true //开启跳页
                ,jump: function(obj, first){
                    if(!first){
                        Ajaxpage(obj.curr)
                    }
                    $('#allpage').html('第'+ obj.curr +'页，共'+ page.total_page +'页');
                }
            });
        });
    }
    // 搜索表单
    $("#search").click(function () {
        Ajaxpage(1);
    });
    // 编辑
    function editEngineers(id) {
        window.location.href = "{:url('Engineers/editEngineers')}?id=" + id;
    }
</script>
